Code:
LRESULT CALLBACK MainWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch(uMsg)
{
case WM_CLOSE:
if(MessageBox(hwnd, "Really quit?", "My application", MB_OKCANCEL)==IDOK)
DestroyWindow(hwnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
case WM_PAINT:
DrawPixels(hwnd);
break;
case WM_KEYDOWN:
{
switch(wParam)
{
case VK_UP:
y = y + 5;
break;
default:
break;
}
}
break;
default:
return DefWindowProc(hwnd, uMsg, wParam, lParam);
}
return 0;
}
Code for DrawPixels function is also enclosed for reference purpose:
Code:
void DrawPixels(HWND hwnd)
{
PAINTSTRUCT ps;
RECT r;
GetClientRect(hwnd, &r);
HDC hdc = BeginPaint(hwnd, &ps);
SetPixel(hdc, -5 + x, y, RGB(0,0,0));
SetPixel(hdc, -4 + x, y, RGB(0,0,0));
SetPixel(hdc, -3 + x, y, RGB(0,0,0));
SetPixel(hdc, 3 + x, y, RGB(0,0,0));
SetPixel(hdc, 4 + x, y, RGB(0,0,0));
SetPixel(hdc, 5 + x, y, RGB(0,0,0));
SetPixel(hdc, x, -5 + y, RGB(0,0,0));
SetPixel(hdc, x, -4 + y, RGB(0,0,0));
SetPixel(hdc, x, -3 + y, RGB(0,0,0));
SetPixel(hdc, x, 3 + y, RGB(0,0,0));
SetPixel(hdc, x, 4 + y, RGB(0,0,0));
SetPixel(hdc, x, 5 + y, RGB(0,0,0));
EndPaint(hwnd, &ps);
}